package dao

import "go/models"

func Addfamily(family models.Familytree) error {

	err := db.Table("family").Create(&family).Error
	return err
}
func Delfamily(id int) error {
	err := db.Table("family").Where("id = ?", id).Update("isdel", true).Error
	return err
}
func Updatefamily(family models.Familytree) error {
	id := family.Id
	err := db.Table("family").Where("id = ?", id).Updates(&family).Error
	return err
}

func Getfamily(familyParam map[string]interface{}) ([]models.Familytree, int64, error) {
	var familyData []models.Familytree
	page := familyParam["page"].(int)
	pageSize := familyParam["limit"].(int)
	searchName := familyParam["searchName"].(string)
	var total int64
	err := db.Table("family").Where("id like ?", searchName+"%").Order("id ASC").Count(&total).Offset((page - 1) * pageSize).Limit(pageSize).Find(&familyData).Error
	return familyData, total, err
}
